
/** 
 * 获取指定时间
 * @param timestamp 时间戳
 * @param format 时间显示格式 年月日 时分秒
 *  */
export function getFormatTime(timestamp, format = 'YYYY-MM-DD hh:mm:ss') {
  if (!timestamp) return '';

  const length = timestamp.toString().length;
  if (length != 13) {
    // 将时间戳统一为毫秒级时间戳
    const deffer = 13 - length;
    timestamp *= 10 ** deffer;
  }

  const newDate = new Date();
  newDate.setTime(timestamp);
  const YEAR = newDate.getFullYear();
  const MONTH = (newDate.getMonth() + 1).toString().padStart(2, '0');
  const DAY = newDate.getDate().toString().padStart(2, '0');
  const HOUR = newDate.getHours().toString().padStart(2, '0');
  const MINUTE = newDate.getMinutes().toString().padStart(2, '0');
  const SECOND = newDate.getSeconds().toString().padStart(2, '0');
  format = format.replace('YYYY', YEAR);
  format = format.replace('MM', MONTH);
  format = format.replace('DD', DAY);
  format = format.replace('hh', HOUR);
  format = format.replace('mm', MINUTE);
  format = format.replace('ss', SECOND);
  return format;
}

/**
 * 获取当前时间时间戳
 * **/
export function getNowTime() {
  return new Date().getTime();
}
